//
//  TZTopView.swift
//  WeiboWithSwift
//
//  Created by 涂真 on 15/12/22.
//  Copyright © 2015年 涂真. All rights reserved.
//

import UIKit
import SDWebImage

class TZStatusTopView: UIView {
    
    ///微博信息系属性
    var status:TZStatus?{
        didSet{
            //设置头像
            if let profileUrlStr  = status?.user?.profile_image_url{
                let profileUrl = NSURL(string: profileUrlStr)
                iconView.sd_setImageWithURL(profileUrl)
            }
            //设置昵称
            nameLabel.text = status?.user?.screen_name
            //设置vip等级
            vipView.image = status?.user?.mbrankImage
                //设置发布时间
            //Tue Dec 22 22:38:43 +0800 2015
            timeLabel.text = "刚刚"
            //设置微博来源
//<a href=\"http://app.weibo.com/t/feed/5B6hUc\" rel=\"nofollow\">iPhone 6s Plus</a>
            sourceLabel.text = "iphone6s"
            //设置认证图标   认证类型, 没有认证:-1   认证用户:0  企业认证:2,3,5  达人:220
            verifiedView.image = status?.user?.verifiedImage
        }
    }
    
    //MARK: - 构造方法
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }

    
    
    //MARK: - 准备UI
    func prepareUI(){
        //添加控件
        addSubview(iconView)
        addSubview(vipView)
        addSubview(nameLabel)
        addSubview(verifiedView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        //约束头像
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        //约束认证图标
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint.init(x: 3.5, y: 3.5))
        //约束昵称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint.init(x: 8, y: 1.5))
        //约束vip等级
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize.init(width: 14, height: 14), offset: CGPoint.init(x: 8, y: 0))
        //约束发布时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint.init(x: 8, y: -1.5))
        //约束来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint.init(x: 8, y: 0))
    }
    
    //MARK: - 懒加载
    ///头像
    lazy var iconView:UIImageView = {
    let imageView = UIImageView(image: UIImage(named: "avatar"))
        imageView.layer.cornerRadius = 17.5
        imageView.layer.masksToBounds = true
        return imageView
    }()
    ///vip等级
    lazy var vipView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    ///用户昵称
    lazy var nameLabel:UILabel = {
        //253,114,54
        let label = UILabel()
        label.font = UIFont.boldSystemFontOfSize(12)
        label.textColor = UIColor(red: 252/255.0, green: 101/255.0, blue: 41/255.0, alpha: 1)
        return label
    }()
    ///认证图标
    lazy var verifiedView = UIImageView(image: nil)
    ///发布时间
    lazy var timeLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(9)
        return label
    }()
    ///微博来源
    lazy var sourceLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(9)
        return label
    }()
    
}
